﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SN.Models;

namespace SN.Report
{
    public partial class FormAdd : Form
    {
        public SN.Models.T_Report Report;

        public FormAdd()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FormChooseClass frm = new FormChooseClass();
            if (frm.ShowDialog() == DialogResult.OK)
            {
                this.txtClassId.Text = frm.Classes.Classes_ID; //类型ID
                this.txtClassName.Text = frm.Classes.Classes_Name; //类型名称
            }
            else
            {
                return;
            }
        }
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtClassId.Text))
            {
                MessageBox.Show("请选择报表分类!", "提示!");
                return;
            }
            if (string.IsNullOrWhiteSpace(comboBox1.Text))
            {
                MessageBox.Show("请选择报表周期!", "提示!");
                return;
            }
            if (string.IsNullOrWhiteSpace(comboBox2.Text))
            {
                MessageBox.Show("请选择报表下发类型!", "提示!");
                return;
            }
            //判断类别是否存在
            if (!SN.Data.DBUtility.DB.Exists<T_Classes>(T_Classes._.Classes_ID == txtClassId.Text.Trim()))
            {
                MessageBox.Show("报表分类数据在报表分类数据表中不存在该类别!", "提示!", MessageBoxButtons.OK);
                return;
            }
            Report = new Models.T_Report();
            Report.Report_ClassesID = txtClassId.Text.Trim();
            Report.Report_Cycle = (comboBox1.SelectedIndex + 1).ToString("00"); //报表周期
            Report.Report_Xflx = (comboBox2.SelectedIndex).ToString(); //下发类型
            Report.Report_Sfmb = Convert.ToInt16(checkBox1.Checked); //是否使用模板 5000W客户使用
            Report.Report_Name = txtBame.Text;
            Report.Report_Sfky = Convert.ToInt16(checkBox_sfky.Checked).ToString(); //报表是否可用

            this.DialogResult = DialogResult.OK;
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void FormAdd_Load(object sender, EventArgs e)
        {
            this.txtBame.Text = this.Text;
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }
    }
}
